package com.mhouse.network;

import android.os.Handler;
import android.os.Message;
import android.os.SystemClock;

import java.util.Random;

/**
 * @author tempo
 *         on 2015/11/23.
 */
public class Protocal {
    NetworkCallback mCallback;
    Handler mHandler=new Handler(){
        @Override
        public void handleMessage(Message msg) {
          if(msg.what==0){
              mCallback.onSuccess();
          }else{
              mCallback.onError();
          }
        }
    };
    public void load(NetworkCallback callback){
        mCallback=callback;
        new Thread(new Runnable() {
            @Override
            public void run() {
                SystemClock.sleep(2000);
                Random rand = new Random();
                boolean state=rand.nextBoolean();
                if(state) {
                    mHandler.sendEmptyMessage(0);
                }else {
                    mHandler.sendEmptyMessage(1);
                }
            }
        }).start();
    }
}
